package services.sbk_jjgl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import com.PublicSystem;
/**
 * 卡厂付款登记
 * @author host
 *
 */
public class KcjjServices {
	PublicSystem sys = PublicSystem.getInstance();
	/**
	 * 银行下拉框选项
	 * @param sj
	 * @return
	 * @throws Exception
	 */
	public List getYinhang(String sj) throws Exception {
		String sql = "select aaa103,aaa102 from v_ic_az11 where aaa100=?";
		List data = sys.query(sql, new Object[] {sj}, true);
		return data;
	}
	/**
	 * 卡商下拉框选项
	 * @param sj
	 * @return
	 * @throws Exception
	 */
	public List getzkks() throws Exception {
		String sql = "select AZF030,AZF031 from az52 ";
		List data = sys.query(sql, new Object[] {}, true);
		return data;
	}	
	
	public String getkslxr(String ksid) throws Exception {
		String sql = "select AZF032 from az52 where AZF030='"+ksid+"'";
		List data = sys.query(sql, new Object[] {}, true);
		HashMap map=(HashMap) data.get(0);
		return map.get("azf032").toString();
	}
	/**
	 * 到卡数量
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public HashMap getnumber(Object[] obj) throws Exception {
		String sql = "select * from AZ15 where AAZ001=? and AAE008 = ? " ;
		List data = sys.query(sql, obj, true);
		String sql1 = "select * from AZ15 where AAZ001=? and AAE008 = ? and AAZ713 is  null" ;
		List data1 = sys.query(sql1, obj, true);
	    HashMap map =new HashMap();
	    if(data.size()>0){
	    	map=(HashMap)data.get(0);
	    }
		if(data.size()==0){
			map.put("error","该批次银行无送交记录！");
		}
		if(data.size()>0&&data1.size()==0){
			map.put("error","该批次银行已经付款登记！");
		}
		
		return map;
	}	
	/**
	 * 到卡数量
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public HashMap getnumber1(Object[] obj) throws Exception {
		String sql = "select * from AZ15 where AAZ001=? and AAE008 = ? " ;
		List data = sys.query(sql, obj, true);
	    HashMap map =new HashMap();
	    if(data.size()>0){
	    	map=(HashMap)data.get(0);
	    	if(map.get("aaz713").toString()==""){
	    		map.clear();
	    		map.put("error","该批次银行无登记记录！");
	    	}
	    }
		if(data.size()==0){
			map.put("error","该批次银行无送交记录！");
		}
		return map;
	}	
	/**
	 * 导出数据量
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public HashMap getdcnumber(String aaz001,String  aae008) throws Exception {
		String sql = "select * from AZ15 where AAZ001='"+aaz001+"' and AAE008 = '"+aae008+"' " ;
		List data = sys.query(sql,new Object[]{}, true);
		String sql1 = "select * from AZ16 where AAZ001='"+aaz001+"' and AAE008 = '"+aae008+"' and aaz752='1'" ;
		List data1 = sys.query(sql1,new Object[]{}, true);
	    HashMap map =new HashMap();
	    if(data1.size()>0){
			map=(HashMap) data1.get(0);
		}
	    if(data.size()>0){
	    	map.put("error","本批次银行已经登记！");
	    }
		if(data1.size()==0){
			map.put("error","该批次银行无送交记录！");
		}
		return map;
	}
	/**
	 * 卡厂付款登记
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public String kcfkdj(HashMap map) throws Exception{			
		String sql = "update az15 set aaz713 ='" + map.get("aaz713") +
				"' ,aaz714 = to_date(substr('" + map.get("aaz714") + "',1,10),'yyyy-mm-dd ') ," +
				"aae036 = sysdate , aaz715='"+map.get("userid")+"' ,aaz716=sysdate where aaz001='" + map.get("aaz001") + "' and aae008='" + map.get("aae008") + "' " ;
		sys.executeSql(sql);
		return "登记成功！";
	} 	
	/**
	 * 交卡厂制卡登记
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public String jkczkdj(HashMap obj) throws Exception{	

		String ss = sys.callDBFuncProce("ic_az20.set_kczkdj", "function", obj).toString();
		String[] str = ss.split("&");
		String result = str[0];
		return result;
	} 	
	/**
	 * 卡厂付款登记查询
	 * @param obj
	 * @param parms
	 * @return
	 * @throws Exception
	 */
	public HashMap getUnit(Object[] obj, HashMap parms) throws Exception {
		String sql = "select * from v_az15 where aaz001 =? and aae008 =?";
		return  sys.getGrid(sql, obj, parms, true);
	}
}
